package com.kiven.thread;

import java.util.Random;

public class ThreadScopeShareData {
	private static int data = 0;
	
	public static void main(String[] args) {
		for (int i=0; i<2; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					data = new Random().nextInt();
					System.out.println( Thread.currentThread().getName() 
							+ " has put the data " + data);
					
					new A().get();
					new B().get();
				}
			}).start();
		}
//		new Thread(new Runnable() {
//			@Override
//			public void run() {
//				data = new Random().nextInt();
//				System.out.println( Thread.currentThread().getName() 
//						+ " has put the data " + data);
//				
//				new A().get();
//				new B().get();
//			}
//		}).start();
//		
//		new Thread(new Runnable() {
//			@Override
//			public void run() {
//				data = new Random().nextInt();
//				System.out.println( Thread.currentThread().getName() 
//						+ " has put the data " + data);
//				
//				new A().get();
//				new B().get();
//			}
//		}).start();
		
	}
	
	static class A {
		public void get() {
			System.out.println("A " + Thread.currentThread().getName() 
					+ " get the data " + data);
		}
	}
	
	static class B {
		public void get() {
			System.out.println("B " + Thread.currentThread().getName() 
					+ " get the data " + data);
		}
	}
}
